(function() {
  app.controller('my_infoCtrl', function($rootScope, $scope, $state, tradeApi, alertTip, header_m) {
    $scope.init = function() {
      tradeApi.query({
        funcId: '300002',
        data: {}
      }).then(function(res) {
        $scope.client_info = res;
        if ($scope.client_info.client_type) {
          $scope.abled = true;
          $scope.checkedState = $scope.client_info.client_type;
        } else {
          header_m.set({
            txt_r: '保存',
            fun_r: function() {
              $scope.myInfoConfirm = true;
            },
          });

          $scope.checked('0');
        }
      });
    };
    $scope.checked = function(i) {
      if ($scope.abled) {
        return;
      }
      $scope.checkedState = i;
      $scope.client_info.client_type = i;
    };
    $scope.reset = function() {
      $scope.client_info.client_name = '';
      $scope.client_info.id_no = '';
      $scope.client_info.organization_name = '';
      $scope.client_info.organization_no = '';
      $scope.myInfoConfirm = false;
    };
    $scope.submit = function() {
      $scope.myInfoConfirm = false;
      tradeApi.query({
        funcId: '300003',
        data: $scope.client_info
      }).then(function(res) {
        alertTip.open({
          msg: '修改成功',
          state: 1,
        });
        $state.go('my-info', null, { reload: true });
      });
    };
  });
})();
